package com.hzbank.interbankplus.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 配置文件工具类
 * 
 * @author wuyuguang
 * @createtime 2016年5月25日 上午10:38:54
 */
public class PropertyUtils {
	private static Logger logger = LoggerFactory.getLogger(PropertyUtils.class);

	private static PropertyUtils utils = new PropertyUtils();
	
	public static PropertyUtils getInstance(){
		return utils;
	}
	
	private Properties properties;

//	private List<String> filePathes;

	private String path = getClass().getResource("/").getPath();

	private PropertyUtils() {
		init();
	}

	public void init() {
		logger.debug("init PropertyUtils ...");
		properties = new Properties();
		String fullPath = path + "conf/application.properties";
		try {
			logger.debug("加载配置文件:{}", fullPath);
			properties.load(new FileInputStream(fullPath));
		} catch (IOException e) {
			logger.error("PropertyUtils加载配置文件出错:", e);
		}
	}

	public void load(String path) {
		try {
			properties.load(new FileInputStream(path));
		} catch (IOException e) {
			logger.error("PropertyUtils手动加载配置【" + path + "】出错:", e);
		}
	}

	public String getProperty(String key){
		return properties.getProperty(key);
	}
}
